package offer.tree;

public class BinaryTree {

    public TreeNode setBinaryTree() {
        TreeNode G = new TreeNode("G");
        TreeNode D = new TreeNode("D");
        TreeNode E = new TreeNode("E", G, null);
        TreeNode B = new TreeNode("B", D, E);
        TreeNode H = new TreeNode("H");
        TreeNode I = new TreeNode("I");
        TreeNode F = new TreeNode("F", H, I);
        TreeNode C = new TreeNode("C", null, F);
        // 构造根节点
        TreeNode root = new TreeNode("A", B, C);
        return root;
    }

    public static void preSearch(TreeNode root) {
        if (root != null) {
            System.out.print(root.val + " ");
            preSearch(root.left);
            preSearch(root.right);
        }
    }

    public static void midSearch(TreeNode root) {
        if (root != null) {
            midSearch(root.left);
            System.out.print(root.val + " ");
            midSearch(root.right);
        }
    }

    public static void bacSearch(TreeNode root) {
        if (root != null) {
            bacSearch(root.left);
            bacSearch(root.right);
            System.out.print(root.val + " ");
        }
    }

}
